﻿using NHibernate.Tool.hbm2ddl;

namespace Inovout.Repositories
{
    public class DatabaseInstaller
    {
        public void InstallSchema()
        {
            foreach (NHibernate.Cfg.Configuration configuration in ComponentRegistry.ResolveAll<NHibernate.Cfg.Configuration>())
            {
                SchemaExport schemaExport = new SchemaExport(configuration);
                schemaExport.Drop(true, true); 
                schemaExport.Create(true, true);
               // schemaExport.Execute(false, true, false);
            }

            InstallInitializedData();
        }
        public void UpdateSchem()
        {
            foreach (NHibernate.Cfg.Configuration configuration in ComponentRegistry.ResolveAll<NHibernate.Cfg.Configuration>())
            {
                SchemaUpdate schemaUpdate = new SchemaUpdate(configuration);
                schemaUpdate.Execute(false, true);
            }
        }
        public virtual void InstallInitializedData()
        {
            foreach (DataInitiator dataInitiator in ComponentRegistry.ResolveAll<DataInitiator>())
            {
                dataInitiator.Initializate();
            }
        }
    }
}
